/*
 *   This file is part of MiniGUI, a mature cross-platform windowing 
 *   and Graphics User Interface (GUI) support system for embedded systems
 *   and smart IoT devices.
 * 
 *   Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd.
 *   Copyright (C) 1998~2002, WEI Yongming
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 * 
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 * 
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *   Or,
 * 
 *   As this program is a library, any link to this program must follow
 *   GNU General Public License version 3 (GPLv3). If you cannot accept
 *   GPLv3, you need to be licensed from FMSoft.
 * 
 *   If you have got a commercial license of this program, please use it
 *   under the terms and conditions of the commercial license.
 * 
 *   For more information about the commercial license, please refer to
 *   <http://www.minigui.com/en/about/licensing-policy/>.
 */
/*
** unicode-bidi-tables.h: the Unicode BIDI tables.
** 
** Created by VincentWei at 2018/08/27
*/

#ifndef _UNICODE_BIDI_TABLES_H
#define _UNICODE_BIDI_TABLES_H

typedef struct _bidichar_type_map
{
    Uint32    type;       // Type of Unicode characters
    Glyph32   glyph;      // Starting index of Unicode character
    Uint8     count;      // Total number of Unicode characters of same type starting from glyphn
} BIDICHAR_TYPE_MAP;

static const BIDICHAR_TYPE_MAP __mg_unicode_bidi_char_type_map []=
{
    { BIDI_TYPE_ON,    0x0000, 0x06},
    { BIDI_TYPE_NSM,   0x0006, 0x04},
    { BIDI_TYPE_BS,    0x000a, 0x01},
    { BIDI_TYPE_ON,    0x000b, 0x02},
    { BIDI_TYPE_BS,    0x000d, 0x01},
    { BIDI_TYPE_ON,    0x000e, 0x05},
    { BIDI_TYPE_WS,    0x0013, 0x01},
    { BIDI_TYPE_ON,    0x0014, 0x08},
    { BIDI_TYPE_ON,    0x001c, 0x04},
    { BIDI_TYPE_WS,    0x0020, 0x01},
    { BIDI_TYPE_ON,    0x0021, 0x02},
    { BIDI_TYPE_ET,    0x0023, 0x03},
    { BIDI_TYPE_ON,    0x0026, 0x05},
    { BIDI_TYPE_ET,    0x002b, 0x01},
    { BIDI_TYPE_CS,    0x002c, 0x01},
    { BIDI_TYPE_ES,    0x002d, 0x01},
    { BIDI_TYPE_CS,    0x002e, 0x02},
    { BIDI_TYPE_EN,    0x0030, 0x0a},
    { BIDI_TYPE_CS,    0x003a, 0x01},
    { BIDI_TYPE_ON,    0x003b, 0x06},
    { BIDI_TYPE_LTR,   0x0041, 0x1a},
    { BIDI_TYPE_ON,    0x005b, 0x02},
    { BIDI_TYPE_ON,    0x005d, 0x03},
    { BIDI_TYPE_NSM,   0x0060, 0x01},
    { BIDI_TYPE_LTR,   0x0061, 0x1a},
    { BIDI_TYPE_ON,    0x007b, 0x01},
    { BIDI_TYPE_SS,    0x007c, 0x01},
    { BIDI_TYPE_ON,    0x007d, 0x03},
    { BIDI_TYPE_BN,    0x0080, 0x05},
    { BIDI_TYPE_BS,    0x0085, 0x01},
    { BIDI_TYPE_BN,    0x0086, 0x1a},
    { BIDI_TYPE_CS,    0x00a0, 0x01},
    { BIDI_TYPE_ON,    0x00a1, 0x01},
    { BIDI_TYPE_ET,    0x00a2, 0x04},
    { BIDI_TYPE_ON,    0x00a6, 0x04},
    { BIDI_TYPE_LTR,   0x00aa, 0x01},
    { BIDI_TYPE_ON,    0x00ab, 0x05},
    { BIDI_TYPE_ET,    0x00b0, 0x02},
    { BIDI_TYPE_EN,    0x00b2, 0x02},
    { BIDI_TYPE_ON,    0x00b4, 0x01},
    { BIDI_TYPE_LTR,   0x00b5, 0x01},
    { BIDI_TYPE_ON,    0x00b6, 0x03},
    { BIDI_TYPE_EN,    0x00b9, 0x01},
    { BIDI_TYPE_LTR,   0x00ba, 0x01},
    { BIDI_TYPE_ON,    0x00bb, 0x05},
    { BIDI_TYPE_LTR,   0x00c0, 0x17},
    { BIDI_TYPE_ON,    0x00d7, 0x01},
    { BIDI_TYPE_LTR,   0x00d8, 0x1f},
    { BIDI_TYPE_ON,    0x00f7, 0x01},
    { BIDI_TYPE_LTR,   0x00f8, 0x29},
    { BIDI_TYPE_LTR,   0x0222, 0x12},
    { BIDI_TYPE_LTR,   0x0250, 0x5e},
    { BIDI_TYPE_LTR,   0x02b0, 0x09},
    { BIDI_TYPE_ON,    0x02b9, 0x02},
    { BIDI_TYPE_LTR,   0x02bb, 0x07},
    { BIDI_TYPE_ON,    0x02c2, 0x0e},
    { BIDI_TYPE_LTR,   0x02d0, 0x02},
    { BIDI_TYPE_ON,    0x02d2, 0x0e},
    { BIDI_TYPE_LTR,   0x02e0, 0x05},
    { BIDI_TYPE_ON,    0x02e5, 0x09},
    { BIDI_TYPE_LTR,   0x02ee, 0x01},
    { BIDI_TYPE_NSM,   0x0300, 0x50},
    { BIDI_TYPE_NSM,   0x0360, 0x10},
    { BIDI_TYPE_LTR,   0x0400, 0x83},
    { BIDI_TYPE_NSM,   0x0483, 0x04},
    { BIDI_TYPE_NSM,   0x0488, 0x02},
    { BIDI_TYPE_LTR,   0x048a, 0x45},
    { BIDI_TYPE_LTR,   0x04d0, 0x26},
    { BIDI_TYPE_LTR,   0x04f8, 0x02},
    { BIDI_TYPE_LTR,   0x0500, 0x10},
    { BIDI_TYPE_AL,    0x0591, 0x11},
    { BIDI_TYPE_AL,    0x05a3, 0x17},
    { BIDI_TYPE_AL,    0x05bb, 0x0A},
    { BIDI_TYPE_AL,    0x05d0, 0x1B},
    { BIDI_TYPE_AL,    0x05f0, 0x05},
    { BIDI_TYPE_CS,    0x060c, 0x01},
    { BIDI_TYPE_AL,    0x061b, 0x01},
    { BIDI_TYPE_AL,    0x061f, 0x01},
    { BIDI_TYPE_AL,    0x0621, 0x1a},
    { BIDI_TYPE_AL,    0x0640, 0x0b},
    { BIDI_TYPE_NSM,   0x064b, 0x0b},
    { BIDI_TYPE_AN,    0x0660, 0x0a},
    { BIDI_TYPE_ET,    0x066a, 0x01},
    { BIDI_TYPE_AN,    0x066b, 0x02},
    { BIDI_TYPE_AL,    0x066d, 0x03},
    { BIDI_TYPE_NSM,   0x0670, 0x01},
    { BIDI_TYPE_AL,    0x0671, 0x65},
    { BIDI_TYPE_NSM,   0x06d6, 0x07},
    { BIDI_TYPE_AL,    0x06dd, 0x01},
    { BIDI_TYPE_NSM,   0x06de, 0x07},
    { BIDI_TYPE_AL,    0x06e5, 0x02},
    { BIDI_TYPE_NSM,   0x06e7, 0x02},
    { BIDI_TYPE_ON,    0x06e9, 0x01},
    { BIDI_TYPE_NSM,   0x06ea, 0x04},
    { BIDI_TYPE_EN,    0x06f0, 0x0a},
    { BIDI_TYPE_AL,    0x06fa, 0x05},
    { BIDI_TYPE_LTR,   0x0e01, 0x30},
    { BIDI_TYPE_NSM,   0x0e31, 0x01},
    { BIDI_TYPE_LTR,   0x0e32, 0x02},
    { BIDI_TYPE_LTR,   0x0e34, 0x07},
    { BIDI_TYPE_ET,    0x0e3f, 0x01},
    { BIDI_TYPE_LTR,   0x0e40, 0x07},
    { BIDI_TYPE_LTR,   0x0e47, 0x08},
    { BIDI_TYPE_LTR,   0x0e4f, 0x0d},
    { BIDI_TYPE_LTR,   0x1e00, 0x9c},
    { BIDI_TYPE_LTR,   0x1ea0, 0x5a},
    { BIDI_TYPE_WS,    0x2000, 0x0b},
    { BIDI_TYPE_BN,    0x200b, 0x03},
    { BIDI_TYPE_LTR,   0x200e, 0x01},
    { BIDI_TYPE_RTL,   0x200f, 0x01},
    { BIDI_TYPE_ON,    0x2010, 0x18},
    { BIDI_TYPE_WS,    0x2028, 0x01},
    { BIDI_TYPE_BS,    0x2029, 0x01},
    { BIDI_TYPE_LRE,   0x202a, 0x01},
    { BIDI_TYPE_RLE,   0x202b, 0x01},
    { BIDI_TYPE_PDF,   0x202c, 0x01},
    { BIDI_TYPE_LRO,   0x202d, 0x01},
    { BIDI_TYPE_RLO,   0x202e, 0x01},
    { BIDI_TYPE_WS,    0x202f, 0x01},
    { BIDI_TYPE_ET,    0x2030, 0x05},
    { BIDI_TYPE_ON,    0x2035, 0x1e},
    { BIDI_TYPE_ON,    0x2057, 0x01},
    { BIDI_TYPE_WS,    0x205f, 0x01},
    { BIDI_TYPE_BN,    0x2060, 0x04},
    { BIDI_TYPE_BN,    0x206a, 0x06},
    { BIDI_TYPE_EN,    0x2070, 0x01},
    { BIDI_TYPE_LTR,   0x2071, 0x01},
    { BIDI_TYPE_EN,    0x2074, 0x06},
    { BIDI_TYPE_ET,    0x207a, 0x02},
    { BIDI_TYPE_ON,    0x207c, 0x03},
    { BIDI_TYPE_LTR,   0x207f, 0x01},
    { BIDI_TYPE_EN,    0x2080, 0x0a},
    { BIDI_TYPE_ET,    0x208a, 0x02},
    { BIDI_TYPE_ON,    0x208c, 0x03},
    { BIDI_TYPE_ET,    0x20a0, 0x12},
    { BIDI_TYPE_NSM,   0x20d0, 0x1b},
    { BIDI_TYPE_ON,    0x2100, 0x02},
    { BIDI_TYPE_LTR,   0x2102, 0x01},
    { BIDI_TYPE_ON,    0x2103, 0x04},
    { BIDI_TYPE_LTR,   0x2107, 0x01},
    { BIDI_TYPE_ON,    0x2108, 0x02},
    { BIDI_TYPE_LTR,   0x210a, 0x0a},
    { BIDI_TYPE_ON,    0x2114, 0x01},
    { BIDI_TYPE_LTR,   0x2115, 0x01},
    { BIDI_TYPE_ON,    0x2116, 0x03},
    { BIDI_TYPE_LTR,   0x2119, 0x05},
    { BIDI_TYPE_ON,    0x211e, 0x06},
    { BIDI_TYPE_LTR,   0x2124, 0x01},
    { BIDI_TYPE_ON,    0x2125, 0x01},
    { BIDI_TYPE_LTR,   0x2126, 0x01},
    { BIDI_TYPE_ON,    0x2127, 0x01},
    { BIDI_TYPE_LTR,   0x2128, 0x01},
    { BIDI_TYPE_ON,    0x2129, 0x01},
    { BIDI_TYPE_LTR,   0x212a, 0x04},
    { BIDI_TYPE_ET,    0x212e, 0x01},
    { BIDI_TYPE_LTR,   0x212f, 0x03},
    { BIDI_TYPE_ON,    0x2132, 0x01},
    { BIDI_TYPE_LTR,   0x2133, 0x07},
    { BIDI_TYPE_ON,    0x213a, 0x01},
    { BIDI_TYPE_LTR,   0x213d, 0x03},
    { BIDI_TYPE_ON,    0x2140, 0x05},
    { BIDI_TYPE_LTR,   0x2145, 0x05},
    { BIDI_TYPE_ON,    0x214a, 0x02},
    { BIDI_TYPE_ON,    0x2153, 0x0d},
    { BIDI_TYPE_LTR,   0x2160, 0x24},
    { BIDI_TYPE_ON,    0x2190, 0x82},
    { BIDI_TYPE_ET,    0x2212, 0x02},
    { BIDI_TYPE_ON,    0x2214, 0x22},
    { BIDI_TYPE_LTR,   0x2336, 0x45},
    { BIDI_TYPE_ON,    0x237b, 0x1a},
    { BIDI_TYPE_LTR,   0x2395, 0x01},
    { BIDI_TYPE_ON,    0x2396, 0x39},
    { BIDI_TYPE_ON,    0x2400, 0x27},
    { BIDI_TYPE_ON,    0x2440, 0x0b},
    { BIDI_TYPE_EN,    0x2460, 0x3c},
    { BIDI_TYPE_LTR,   0x249c, 0x4e},
    { BIDI_TYPE_EN,    0x24ea, 0x01},
    { BIDI_TYPE_ON,    0x24eb, 0x14},
    { BIDI_TYPE_ON,    0x2500, 0x14},
    { BIDI_TYPE_ON,    0x2616, 0x02},
    { BIDI_TYPE_ON,    0x2619, 0x65},
    { BIDI_TYPE_ON,    0x2680, 0x0a},
    { BIDI_TYPE_ON,    0x2701, 0x04},
    { BIDI_TYPE_ON,    0x2706, 0x04},
    { BIDI_TYPE_ON,    0x270c, 0x1c},
    { BIDI_TYPE_ON,    0x2729, 0x23},
    { BIDI_TYPE_ON,    0x274d, 0x01},
    { BIDI_TYPE_ON,    0x274f, 0x04},
    { BIDI_TYPE_ON,    0x2756, 0x01},
    { BIDI_TYPE_ON,    0x2758, 0x07},
    { BIDI_TYPE_ON,    0x2761, 0x34},
    { BIDI_TYPE_ON,    0x2798, 0x18},
    { BIDI_TYPE_ON,    0x27b1, 0x0e},
    { BIDI_TYPE_ON,    0x27d0, 0x1c},
    { BIDI_TYPE_ON,    0x27f0, 0x10},
    { BIDI_TYPE_ON,    0x2e80, 0x1a},
    { BIDI_TYPE_ON,    0x2e9b, 0x59},
    { BIDI_TYPE_ON,    0x2f00, 0xd6},
    { BIDI_TYPE_ON,    0x2ff0, 0x0c},
    { BIDI_TYPE_WS,    0x3000, 0x01},
    { BIDI_TYPE_ON,    0x3001, 0x04},
    { BIDI_TYPE_LTR,   0x3005, 0x03},
    { BIDI_TYPE_ON,    0x3008, 0x19},
    { BIDI_TYPE_LTR,   0x3021, 0x09},
    { BIDI_TYPE_NSM,   0x302a, 0x06},
    { BIDI_TYPE_ON,    0x3030, 0x01},
    { BIDI_TYPE_LTR,   0x3031, 0x05},
    { BIDI_TYPE_ON,    0x3036, 0x02},
    { BIDI_TYPE_LTR,   0x3038, 0x05},
    { BIDI_TYPE_ON,    0x303d, 0x03},
    { BIDI_TYPE_LTR,   0x3041, 0x56},
    { BIDI_TYPE_NSM,   0x3099, 0x02},
    { BIDI_TYPE_ON,    0x309b, 0x02},
    { BIDI_TYPE_LTR,   0x309d, 0x03},
    { BIDI_TYPE_ON,    0x30a0, 0x01},
    { BIDI_TYPE_LTR,   0x30a1, 0x5a},
    { BIDI_TYPE_ON,    0x30fb, 0x01},
    { BIDI_TYPE_LTR,   0x30fc, 0x04},
    { BIDI_TYPE_LTR,   0x3105, 0x28},
    { BIDI_TYPE_LTR,   0x3131, 0x5e},
    { BIDI_TYPE_LTR,   0x3190, 0x28},
    { BIDI_TYPE_LTR,   0x31f0, 0x2d},
    { BIDI_TYPE_LTR,   0x3220, 0x24},
    { BIDI_TYPE_ON,    0x3251, 0x0f},
    { BIDI_TYPE_LTR,   0x3260, 0x1c},
    { BIDI_TYPE_LTR,   0x327f, 0x32},
    { BIDI_TYPE_ON,    0x32b1, 0x0f},
    { BIDI_TYPE_LTR,   0x32c0, 0x0c},
    { BIDI_TYPE_LTR,   0x32d0, 0x2f},
    { BIDI_TYPE_LTR,   0x3300, 0x77},
    { BIDI_TYPE_LTR,   0x337b, 0x63},
    { BIDI_TYPE_LTR,   0x33e0, 0x1f},
    { BIDI_TYPE_LTR,   0x3400, 0x01},
    { BIDI_TYPE_LTR,   0x4db5, 0x01},
    { BIDI_TYPE_LTR,   0x4e00, 0x01},
    { BIDI_TYPE_LTR,   0x9fa5, 0x01},
    { BIDI_TYPE_ON,    0xEA00, 0xFF},
    { BIDI_TYPE_ON,    0xEB00, 0xFF},
    { BIDI_TYPE_ON,    0xEC00, 0xFF},
    { BIDI_TYPE_ON,    0xED00, 0xFF},
    { BIDI_TYPE_ON,    0xEE00, 0xFF},
    { BIDI_TYPE_ON,    0xEF00, 0xFF},
    { BIDI_TYPE_LTR,   0xf900, 0x2e},
    { BIDI_TYPE_LTR,   0xfa30, 0x3b},
    { BIDI_TYPE_LTR,   0xfb00, 0x07},
    { BIDI_TYPE_AL,    0xfb50, 0x62},
    { BIDI_TYPE_AL,    0xfbd3, 0x6b},
    { BIDI_TYPE_AL,    0xfc3f, 0x01},
    { BIDI_TYPE_AL,    0xfc40, 0x10},
    { BIDI_TYPE_AL,    0xfc60, 0x90},
    { BIDI_TYPE_AL,    0xfd0a, 0x07},
    { BIDI_TYPE_AL,    0xfd20, 0x10},
    { BIDI_TYPE_AL,    0xfd30, 0x0c},
    { BIDI_TYPE_ON,    0xfd3e, 0x02},
    { BIDI_TYPE_AL,    0xfd50, 0x40},
    { BIDI_TYPE_AL,    0xfd92, 0x36},
    { BIDI_TYPE_AL,    0xfdf0, 0x0d},
    { BIDI_TYPE_NSM,   0xfe00, 0x10},
    { BIDI_TYPE_NSM,   0xfe20, 0x04},
    { BIDI_TYPE_ON,    0xfe30, 0x17},
    { BIDI_TYPE_ON,    0xfe49, 0x07},
    { BIDI_TYPE_CS,    0xfe50, 0x01},
    { BIDI_TYPE_ON,    0xfe51, 0x01},
    { BIDI_TYPE_CS,    0xfe52, 0x01},
    { BIDI_TYPE_ON,    0xfe54, 0x01},
    { BIDI_TYPE_CS,    0xfe55, 0x01},
    { BIDI_TYPE_ON,    0xfe56, 0x09},
    { BIDI_TYPE_ET,    0xfe5f, 0x01},
    { BIDI_TYPE_ON,    0xfe60, 0x02},
    { BIDI_TYPE_ET,    0xfe62, 0x02},
    { BIDI_TYPE_ON,    0xfe64, 0x03},
    { BIDI_TYPE_ON,    0xfe68, 0x01},
    { BIDI_TYPE_ET,    0xfe69, 0x02},
    { BIDI_TYPE_ON,    0xfe6b, 0x01},
    { BIDI_TYPE_AL,    0xfe70, 0x05},
    { BIDI_TYPE_AL,    0xfe76, 0x87},
    { BIDI_TYPE_BN,    0xfeff, 0x01},
    { BIDI_TYPE_ON,    0xff01, 0x02},
    { BIDI_TYPE_ET,    0xff03, 0x03},
    { BIDI_TYPE_ON,    0xff06, 0x05},
    { BIDI_TYPE_ET,    0xff0b, 0x01},
    { BIDI_TYPE_CS,    0xff0c, 0x01},
    { BIDI_TYPE_ET,    0xff0d, 0x01},
    { BIDI_TYPE_CS,    0xff0e, 0x01},
    { BIDI_TYPE_ES,    0xff0f, 0x01},
    { BIDI_TYPE_EN,    0xff10, 0x0a},
    { BIDI_TYPE_CS,    0xff1a, 0x01},
    { BIDI_TYPE_ON,    0xff1b, 0x06},
    { BIDI_TYPE_LTR,   0xff21, 0x1a},
    { BIDI_TYPE_ON,    0xff3b, 0x06},
    { BIDI_TYPE_LTR,   0xff41, 0x1a},
    { BIDI_TYPE_ON,    0xff5b, 0x0b},
    { BIDI_TYPE_LTR,   0xff66, 0x59},
    { BIDI_TYPE_LTR,   0xffc2, 0x06},
    { BIDI_TYPE_LTR,   0xffca, 0x06},
    { BIDI_TYPE_LTR,   0xffd2, 0x06},
    { BIDI_TYPE_LTR,   0xffda, 0x03},
    { BIDI_TYPE_ET,    0xffe0, 0x02},
    { BIDI_TYPE_ON,    0xffe2, 0x03},
    { BIDI_TYPE_ET,    0xffe5, 0x02},
    { BIDI_TYPE_ON,    0xffe8, 0x07},
    { BIDI_TYPE_BN,    0xfff9, 0x03},
    { BIDI_TYPE_ON,    0xfffc, 0x02},
};

static const BIDICHAR_MIRROR_MAP __mg_unicode_mirror_table []=
{
    {0x0028,	0x0029},
    {0x003c,	0x003e},
    {0x005b,	0x005d},
    {0x007b,	0x007d},
    {0x00ab,	0x00bb},
    {0x2039,	0x203a},
    {0x2045,	0x2046},
    {0x207d,	0x207e},
    {0x208d,	0x208e},
    {0x2208,	0x220b},
    {0x2209,	0x220c},
    {0x220a,	0x220d},
    {0x2215,	0x29f5},
    {0x2768,	0x2769},
    {0x276a,	0x276b},
    {0x276c,	0x276d},
    {0x276e,	0x276f},
    {0x2770,	0x2771},
    {0x2772,	0x2773},
    {0x2774,	0x2775},
    {0x27d5,	0x27d6},
    {0x27dd,	0x27de},
    {0x27e2,	0x27e3},
    {0x27e4,	0x27e5},
    {0x27e6,	0x27e7},
    {0x27e8,	0x27e9},
    {0x27ea,	0x27eb},
    {0x3008,	0x3009},
    {0x300a,	0x300b},
    {0x300c,	0x300d},
    {0x300e,	0x300f},
    {0x3010,	0x3011},
    {0x3014,	0x3015},
    {0x3016,	0x3017},
    {0x3018,	0x3019},
    {0x301a,	0x301b},
    {0xff08,	0xff09},
    {0xff1c,	0xff1e},
    {0xff3b,	0xff3d},
    {0xff5b,	0xff5d},
    {0xff5f,	0xff60},
    {0xff62,	0xff63}
};

#endif /* !_UNICODE_BIDI_TABLES_H */

